package com.nimitz.web.controller.module.employee;

import com.nimitz.common.annotation.Log;
import com.nimitz.common.core.controller.BaseController;
import com.nimitz.common.core.domain.AjaxResult;
import com.nimitz.common.core.page.TableDataInfo;
import com.nimitz.common.enums.BusinessType;
import com.nimitz.common.utils.StringUtils;
import com.nimitz.module.employee.domain.EmpPost;
import com.nimitz.module.employee.service.IEmpPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 转岗维护
 */
@RestController
@Api(tags = "人员管理-转岗维护")
@RequestMapping("/module/employee/post")
public class EmpPostController extends BaseController {

    @Resource
    private IEmpPostService postService;

    /**
     * 新增转岗
     *
     * @param post 转岗
     * @return 结果
     */
    @PostMapping
    @ApiOperation(value = "新增转岗")
    @PreAuthorize("@ss.hasPermi('employee:post:add')")
    @Log(title = "人员管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody EmpPost post) {
        post.setCreateBy(getUsername());
        return toAjax(postService.insertPost(post));
    }

    /**
     * 批量删除转岗
     *
     * @param postIds 需要删除的转岗id集合
     * @return 结果
     */
    @DeleteMapping("/{postIds}")
    @ApiOperation(value = "批量删除转岗")
    @PreAuthorize("@ss.hasPermi('employee:post:remove')")
    @Log(title = "人员管理", businessType = BusinessType.DELETE)
    public AjaxResult removes(@PathVariable Integer[] postIds) {
        return toAjax(postService.deletePostByIds(getUsername(), postIds));
    }

    /**
     * 修改转岗
     *
     * @param post 转岗
     * @return 结果
     */
    @PutMapping
    @ApiOperation(value = "修改转岗")
    @PreAuthorize("@ss.hasPermi('employee:post:edit')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody EmpPost post) {
        post.setUpdateBy(getUsername());
        return toAjax(postService.updatePost(post));
    }

    /**
     * 根据转岗id查询人员
     *
     * @param postId 转岗id
     * @return 转岗
     */
    @GetMapping("/{postId}")
    @ApiOperation(value = "根据转岗id查询人员")
    public AjaxResult getInfo(@PathVariable(value = "postId", required = false) Integer postId) {
        AjaxResult ajax = AjaxResult.success();
        if (StringUtils.isNotNull(postId)) {
            EmpPost post = postService.selectPostById(postId);
            ajax.put(AjaxResult.DATA_TAG, post);
        }
        return ajax;
    }

    /**
     * 根据条件查询转岗列表（含分页）
     *
     * @param post 转岗
     * @return 转岗集合
     */

    @PostMapping("/list")
    @ApiOperation(value = "根据条件查询转岗列表（含分页）")
    @PreAuthorize("@ss.hasPermi('employee:post:list')")
    public TableDataInfo list(@RequestBody EmpPost post) {
        startPage();
        List<EmpPost> list = postService.selectPostList(post);
        return getDataTable(list);
    }

    /**
     * 批量提交
     *
     * @param postIds 需要提交的转岗id集合
     * @return 结果
     */
    @PutMapping("/submit/{postIds}")
    @ApiOperation(value = "批量提交")
    @PreAuthorize("@ss.hasPermi('employee:post:submit')")
    @Log(title = "转岗提交", businessType = BusinessType.UPDATE)
    public AjaxResult submit(@PathVariable Integer[] postIds) {
        return toAjax(postService.submitPost(getUsername(), postIds));
    }

    /**
     * 批量驳回
     *
     * @param postIds 需要驳回的转岗id集合
     * @return 结果
     */
    @PutMapping("/reject/{postIds}")
    @ApiOperation(value = "批量驳回")
    @PreAuthorize("@ss.hasPermi('employee:post:reject')")
    @Log(title = "转岗驳回", businessType = BusinessType.UPDATE)
    public AjaxResult reject(@PathVariable Integer[] postIds) {
        return toAjax(postService.rejectPost(getUsername(), postIds));
    }

    /**
     * 批量审核
     *
     * @param postIds 需要驳回的转岗id集合
     * @return 结果
     */
    @PutMapping("/audit/{postIds}")
    @ApiOperation(value = "批量审核")
    @PreAuthorize("@ss.hasPermi('employee:post:audit')")
    @Log(title = "转岗审核", businessType = BusinessType.UPDATE)
    public AjaxResult audit(@PathVariable Integer[] postIds) {
        return toAjax(postService.auditPost(getUsername(), postIds));
    }
}
